package lmscript.postscript.syntax.stack;

import lmscript.postscript.Interpreter;
import lmscript.postscript.syntax.PSArray;
import lmscript.postscript.syntax.PSBoolean;
import lmscript.postscript.syntax.PSDictionary;
import lmscript.postscript.syntax.PSInteger;
import lmscript.postscript.syntax.PSNumber;
import lmscript.postscript.syntax.PSReal;

public class OperandStack extends PSStack {

	private Interpreter interpreter;

	public OperandStack(Interpreter interpreter) {
		this.interpreter = interpreter;
	}

	public void pushNumber(Number n) {
		if (n instanceof Integer) {
			push(new PSInteger(n.intValue()));
		}
		push(new PSReal(n.doubleValue()));
	}

	public void pushNumber(int n) {
		super.push(new PSInteger(n));
	}

	public void pushNumber(double d) {
		super.push(new PSReal(d));
	}

	public PSBoolean popBoolean() {
		return (PSBoolean) pop();
	}

	public PSNumber popNumber() {
		return (PSNumber) pop();
	}

	public PSDictionary popDict() {
		return (PSDictionary) pop();
	}

	public PSArray popArray() {
		return (PSArray) pop();
	}

	public DictionaryStack getDictStack() {
		return this.interpreter.getDictStack();
	}

	public ExecutionStack getExecutionStack() {
		return this.interpreter.getExecutionStack();
	}
}
